<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的评论 - 校园表白墙</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="/css/style.css">
</head>
<body>
    <nav class="navbar navbar-light bg-white shadow-sm">
        <div class="container">
            <button class="btn btn-link" onclick="history.back()">
                <i class="bi bi-arrow-left"></i> 返回
            </button>
            <span class="navbar-text">我的评论</span>
            <div></div>
        </div>
    </nav>
    
    <div class="container mt-3">
        <div id="myCommentsList"></div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        function init() {
            if (!checkLogin()) return;
            loadMyComments();
        }
        
        function loadMyComments() {
            showLoading('#myCommentsList');
            
            request('/comments/my?page=1&size=50')
                .then(data => {
                    if (data.records && data.records.length > 0) {
                        renderComments(data.records);
                    } else {
                        showEmpty('#myCommentsList', '还没有评论哦');
                    }
                })
                .catch(err => {
                    showToast(err.message, 'danger');
                });
        }
        
        function renderComments(comments) {
            let html = '';
            comments.forEach(comment => {
                html += `
                    <div class="card mb-3">
                        <div class="card-body">
                            <div class="comment-content">${comment.content}</div>
                            <div class="text-muted small mt-2">${formatTime(comment.createTime)}</div>
                            <button class="btn btn-sm btn-outline-primary mt-2" onclick="goToPost(${comment.postId})">
                                查看帖子
                            </button>
                        </div>
                    </div>
                `;
            });
            $('#myCommentsList').html(html);
        }
        
        $(document).ready(init);
    </script>
</body>
</html>

